Lists is a section of the Variables pane. It contains 5 commands, 14 reporters, and 2 predicates.
Block | Function | Options |
---|---|---|
Commands (5) | ||
| Runs a command for each item of a list, like map but for commands. | |
add [thing] to @list | Adds an element to the end of a list | |
delete (1 v) of @list | Removes an element of a list. All and last are much faster than other numbers. |
|
insert [thing] at (1 v) of @list | Inserts an element at the specified index. |
|
replace item (1 v) of @list with [thing] | Replaces an element of a list with another element. |
|
Reporters (14) | ||
(list [] @delInput @addInput) | Makes a new list with predetermined values. | Click on the arrows to add or remove inputs. |
(numbers from (1) to (10)) | Creates a new list with numbers ranging from the first input to the second. | |
([] in front of @list) | Makes a linked list with one element and another list. If the second list changes, then so will the output. | |
(item (1 v) of @list) | Gets an item of a list. The first item of a list is 1. |
|
(all but first of @list) | Gets a list containing all elements of a list except the first. This is the inverse of
| |
([length V] of @list) | Gets the specified property of the list. |
|
(index of [thing] in @list) | Finds the first index of an element in a list. If the list does not contain the element, then the result is 0. | |
(map (() @addInput) over @list) | Loops over the list, and returns a new list with values processed by the ring. | |
(keep items (<> @addInput) from @list) | Creates a new list with only the items from the list where the ring reports true, with the same order as the input. | |
(find first item (<> @addInput) in @list) | Finds the first item in a list where the condition in the ring is met, or it returns true with the item as an input. | |
(combine @list using (() @addInput)) | Takes the first element, and successively combines other elements of the list using the function provided. | |
(append @list @list @delInput @verticalEllipsis @addInput) | Concatenates multiple lists like join. It accepts an input list. This block was introduced in Snap! version 6.0 and beyond as a primitive, and is a part of the List Utilities library in previous versions of Snap!. | |
(reshape [] to (4) (3) @delInput @verticalEllipsis @addInput) | Creates a new list from the input list with the specified dimensions. | |
(combinations @list @list @delInput @verticalEllipsis @addInput) | Generates a new list with every possible combination with each item in each list. | |
Predicates (2) | ||
<@list contains [thing]> | Checks if an element is in a list. The element can be any value. | |
<is @list empty?> | Check if a list is empty. | |
Dev Mode Blocks (1) | ||
show table @list | Opens the input list in a dialog. } |